package com.qf.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.house.dao.HouseDao;
import com.qf.house.entity.House;
import com.qf.house.entity.SearchParams;
import com.qf.house.service.HouseService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 房屋信息表(House)表服务实现类
 *
 * @author makejava
 * @since 2024-01-09 14:40:43
 */
@Service("houseService")
public class HouseServiceImpl extends ServiceImpl<HouseDao, House> implements HouseService {

    /**
     * 房屋搜索的业务
     * @param searchParams
     * @return
     */
    @Override
    public List<House> searchHouse(SearchParams searchParams) {

        String keyword = searchParams.getKeyword();
        //eq =  gt >   lt <  ge >=  le <=
        return this.query().and(StringUtils.hasLength(keyword), houseQueryWrapper -> {
                    houseQueryWrapper.like("subject", keyword)
                            .or().like("xiaoqu", keyword)
                            .or().like("city", keyword);
                })
                .eq(searchParams.getJishi() != null, "jishi", searchParams.getJishi())
                .eq(searchParams.getJiting() != null, "jiting", searchParams.getJiting())
                .ge(searchParams.getMinPrice() != null, "price", searchParams.getMinPrice())
                .le(searchParams.getMaxPrice() != null, "price", searchParams.getMaxPrice())
                .list();

        // where (subject like '%?%' or xiaoqu like '%?%' or city like '%?%') and jishi = ? and jiting = ? and price >= ? and price <= ?
    }
}


